import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import libs from "@/libs";

// 加载插件
import "@/plugin/component";
import "@/plugin/filter";
import "@/plugin/vant";
import "@/mixins";

Vue.config.productionTip = false;
Vue.prototype.isDev = process.env.NODE_ENV === "development";
Vue.prototype.libs = libs


var exitTimer = 0
new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    // 获取缓存用户信息
    const userInfo = libs.store.getItem('userinfo')
    if (userInfo) {
      // 存在就开始获取公用信息
      this.$store.dispatch('pre/init')
    }
    
    document.addEventListener("plusready", () => {
      // eslint-disable-next-line no-undef
      plus && plus.key.addEventListener('backbutton', () => {
        // window.history.go(-1);
        if (this.$route.name === 'home' || this.$route.name === 'login') {
          if (Date.now() - exitTimer < 2000) {
            // eslint-disable-next-line no-undef
            plus && plus.runtime.quit();
          } else {
            exitTimer = Date.now()
            this.$toast('再按一次退出应用')
          }
        } else  {
          this.$router.go(-1)
        }
      }, false);
    }) 
  }
}).$mount('#app')
